<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>系统管理首页</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/main.css">
</head>
<body>
<div class="container">
    <div class="row bg-black text-light" style="min-height: 60px;">
        <div class="col-2"><img src="img/1.jpg" width="50%" alt=""></div>
        <div class="col-8 text-center">
            <p>欢迎使用超市管理系统</p>
        </div>
        <div class="col-2">当前用户：admin</div>
    </div>
    <div class="row">
        <div class="col-2 bg-black text-light">
            <li><a href="/main">管理系统首页</a></li>
            <li><a href="/goods">商品管理页</a></li>
            <li><a href="/">供应商管理页</a></li>
        </div>
        <div class="col-10">
            <div class=""><a href="/goodsAdd" class="btn btn-success">新增</a></div>
            <!--            <p th:text="${data}"></p>-->
            <table class="table table-bordered">
                <thead>
                <th>序号</th>
                <th>商品名称</th>
                <th>价格</th>
                <th>数量</th>
                <th>供应商</th>
                <th>管理</th>
                </thead>
                <tbody>
                <tr th:each="goods:${data}">
                    <td th:text="${goods.id}"></td>
                    <td th:text="${goods.name}"></td>
                    <td th:text="${goods.price}"></td>
                    <td th:text="${goods.category}"></td>
                    <td th:text="${goods.supplier}"></td>
                    <td>
                        <button class="btn btn-danger" th:onclick="del([[${goods.getId()}]])">删除</button>
                        <a href="/goodsUpdate?id=[[${goods.getId()}]]">更新</a>
<!--                        <button class="btn btn-success" th:onclick="update([[${goods.getId()}]])">更新</button>-->
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>
<script src="js/jquery.min.js"></script>
<script>
    function del(id){
        //     jquery的post方法ajax方法
        $.post("/api/goodsDelete",{"id":id},function(res){
            console.log(res)
            if(res==1){
                alert("删除成功");
                location.reload();
            }else {
                alert("删除失败");
                location.reload();
            }
        })
    }
    function update(id){
        //     jquery的post方法ajax方法
        $.post("goodsUpdate",{"id":id},function(res){
            console.log(res)
            if(res==1){
                alert("更新成功");
                location.reload();
            }else {
                alert("更新失败");
                location.reload();
            }
        })
    }
</script>